VERSION 5.00
Begin VB.UserControl txtCliente 
   BackColor       =   &H80000013&
   ClientHeight    =   870
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   5385
   ScaleHeight     =   870
   ScaleWidth      =   5385
   Begin VB.CheckBox chkTodos 
      BackColor       =   &H80000013&
      Caption         =   "Todos los clientes"
      Height          =   255
      Left            =   0
      TabIndex        =   4
      Top             =   600
      Visible         =   0   'False
      Width           =   1815
   End
   Begin VB.TextBox txtNombreORazonSocial 
      BackColor       =   &H80000018&
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   960
      Locked          =   -1  'True
      TabIndex        =   2
      Top             =   240
      Width           =   3735
   End
   Begin VB.CommandButton cmdBuscar 
      Height          =   375
      Left            =   4800
      Picture         =   "txtCliente.ctx":0000
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   120
      Width           =   495
   End
   Begin VB.TextBox txtIdCliente 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   0
      MaxLength       =   8
      TabIndex        =   0
      Top             =   240
      Width           =   855
   End
   Begin VB.Label lblCliente 
      BackColor       =   &H80000013&
      Caption         =   "Cliente"
      Height          =   255
      Left            =   0
      TabIndex        =   3
      Top             =   0
      Width           =   2055
   End
End
Attribute VB_Name = "txtCliente"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Event Validado()
Dim mostrarMensaje As Boolean
Event noExiste()


Private Sub cmdBuscar_Click()
dlgConsultaClientes.Show vbModal
If dlgConsultaClientes.idcliente <> 0 Then
    txtIdCliente.text = dlgConsultaClientes.idcliente
    txtIdCliente_Validate (False)
End If
End Sub



Private Sub chkTodos_Click()
If chkTodos.Value = 1 Then
    deshabilitar
Else
    habilitar (True)
End If

End Sub

Private Sub txtIdCliente_LostFocus()
    txtIdCliente_Validate (True)
End Sub

Private Sub txtIdCliente_Validate(Cancel As Boolean)
If txtIdCliente.text <> "" Then
    Dim rec As New ADODB.Recordset
    Set rec = Nothing
    rec.ActiveConnection = cn
    rec.Open "select nombreorazonsocial from cliente where id_cliente = " & txtIdCliente.text
  
    If rec.RecordCount <> 0 Then
      rec.MoveFirst
      txtNombreORazonSocial = rec!nombreorazonsocial
      RaiseEvent Validado
    Else
        If mostrarMensaje Then
            MsgBox "No existe el cliente", vbOKOnly, "Error"
            txtIdCliente.text = ""
            txtNombreORazonSocial.text = ""
            txtIdCliente.SetFocus
        Else
            txtNombreORazonSocial.Enabled = True
            txtNombreORazonSocial.SetFocus
        End If
        RaiseEvent noExiste
    End If
Else
txtNombreORazonSocial.text = ""
End If
End Sub


Public Sub limpiar()
txtIdCliente.text = ""
txtNombreORazonSocial.text = ""
End Sub

Private Sub txtIdCliente_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) = False And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

Public Sub deshabilitar()
txtIdCliente.text = ""
txtNombreORazonSocial.text = ""
txtIdCliente.Enabled = False
cmdBuscar.Enabled = False
End Sub

Public Sub habilitar(b As Boolean)
txtIdCliente.Enabled = b
cmdBuscar.Enabled = b
End Sub

Public Function text() As String
text = txtIdCliente.text
End Function

Public Function Denom() As String
Denom = txtNombreORazonSocial.text
End Function

Public Function settext(texto As String)
txtIdCliente.text = texto
Call txtIdCliente_Validate(False)
End Function
Public Sub validar()
Call txtIdCliente_Validate(False)
End Sub

Private Sub txtIdCliente_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
    SendKeys "{TAB}"
End If
End Sub

Public Sub focus()
    txtIdCliente.SetFocus
End Sub

Public Sub mostrarTodos(b As Boolean)
chkTodos.Visible = b
End Sub
Public Sub setTodos(b As Boolean)
If b Then
    chkTodos.Value = 1
Else
    chkTodos.Value = 0
End If

End Sub
Public Sub setmostrarMensaje(b As Boolean)
mostrarMensaje = b
End Sub

Private Sub UserControl_Initialize()
mostrarMensaje = True
End Sub
Public Function getTodos()
getTodos = chkTodos.Value
End Function
